<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');

class mseries extends MY_Model {

    var $theme_data = array(
        'layout_main' => 'layout',
        'left' => 'include/leftcp',
    );
    public $mytable = "series";
    public $primaryKey = "SER_ID";
    public $resCode = "SERIES";

    function __construct() {
        parent::__construct();
    }

    function field() {
        $fieldData = array();
        $fieldData['PROG_ID'] = 0;
        $fieldData['SER_TITLE'] = '';
        $fieldData['SER_CODE'] = '';
        $fieldData['SER_ORDER'] = 0;
        $fieldData['SER_STATUS'] = 1;
        $fieldData['SER_TIMECREATE'] = time();
        $fieldData['SER_TIMEUPDATE'] = time();
        return $fieldData;
    }

	function gets_in_with_program(array $programs) {
		//return $this->db->query("SELECT   `s`.*, p.PROG_CODE FROM ((select * from series order by SER_ID desc)  as s) JOIN `program` as p ON `p`.`PROG_ID` = `s`.`PROG_ID` WHERE `p`.`PROG_ID` IN (1, 2, 3) group by p.PROG_ID ORDER BY `s`.`SER_ID` desc")->result();
		return 
		$this->db
			->select('*')
			->from($this->mytable . " as s" ) 
			->join('program as p', 'p.PROG_ID = s.PROG_ID')
			->where_in('p.PROG_ID', $programs)
			->order_by('s.SER_ID desc')
			->group_by('p.PROG_ID')
			->get()
			->result();
	}
    function gets_by_program($programId, $limit = 10, $offset = 0) {
        $this->db
                ->order_by('SER_ORDER desc')
                ->order_by('SER_ID desc');

        $series = $this->gets(array(
            'PROG_ID' => $programId,
            'SER_STATUS' => 1));
        return $series;
    }
    public function gets_in($array, $field = '') {
        if ($field=='') $field = $this->primaryKey;
        
    }
}

?>
